package cn.com.dcsgo.settlement.calculator;

import cn.com.dcsgo.settlement.OrderAmountContext;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 运费计算器
 *
 * @author Dcsgo
 * @since 2025/11/17 18:35
 */
@Component
public class FreightCalculator extends AbstractOrderAmountCalculator {
    @Override
    public void calculate(OrderAmountContext orderAmountContext) {
        //商品总金额-折减金额>=99包邮，反之需支付运费10元
        BigDecimal subtract = orderAmountContext.getCommoditiesAmount().subtract(orderAmountContext.getDiscountAmount());
        if (subtract.compareTo(BigDecimal.valueOf(99)) < 0) {
            orderAmountContext.setFreight(BigDecimal.valueOf(10));
        } else {
            orderAmountContext.setFreight(BigDecimal.ZERO);
        }
        if (getNextCalculator() != null) {
            getNextCalculator().calculate(orderAmountContext);
        }
    }
}
